package com.example.setalarm.object;

import com.example.setalarm.R;
import com.example.setalarm.utils.Utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Point;

public class BaseIcon {

	public static final int TYPE_HOME = 1;
	public static final int TYPE_PHONE = 2;
	public static final int TYPE_SMS = 3;

	public static final int STATE_NORMAL = 0;
	public static final int STATE_SCALE_IN = 1;
	public static final int STATE_SCALE_OUT = 2;

	private String[] colors = new String[] { "#4183D7", "#D91E18", "#F9BF3B" };
	protected Context mContext;
	protected int type;
	protected Point pos, pCenter;
	protected float mRadius;
	protected Bitmap mBitmap;
	protected int state;

	public BaseIcon(Context context, int type, float radius) {
		super();
		this.mContext = context;
		this.type = type;
		mRadius = radius;
		state = STATE_NORMAL;
	}

	public void setPos(Point p) {
		pCenter = new Point(p.x, p.y);
		p.x = p.x - getBitmap().getWidth() / 2;
		p.y = p.y - getBitmap().getHeight() / 2;
		this.pos = p;
	}

	public Point getPos() {
		return this.pos;
	}

	public Point getCenter() {
		return this.pCenter;
	}

	public Bitmap getBitmap() {
		if (mBitmap == null) {
			switch (type) {
			case TYPE_HOME:
				mBitmap = BitmapFactory.decodeResource(
						this.mContext.getResources(), R.drawable.unlock_home);

				break;

			case TYPE_PHONE:
				mBitmap = BitmapFactory.decodeResource(
						this.mContext.getResources(), R.drawable.unlock_phone);
				break;
			case TYPE_SMS:
				mBitmap = BitmapFactory.decodeResource(
						this.mContext.getResources(), R.drawable.unlock_sms);
				break;
			}
			// mBitmap = Utils.makeIcon(mRadius, mBitmap,
			// Color.parseColor(colors[type - 1]));
		}
		return mBitmap;
	}

	public int getState() {
		return state;
	}

	public void setState(int state) {
		this.state = state;
	}

	public int getType() {
		return type;
	}

	public void setType(int type) {
		this.type = type;
	}

	public boolean isKiss(float x, float y) {
		if (Math.sqrt(Math.pow(x - (pos.x + mRadius), 2)
				+ Math.pow(y - (pos.y + mRadius), 2)) < mRadius)
			return true;
		return false;
	}

	public void doAction() {

	}
}
